import webapp2

doc = """<!DOCTYPE html> 
<html> 
<head> 
<style type="text/css" media="all"> 
  #navlist li {
    display: inline;
    list-style-type: none;
    padding-right: 20px;
 }  

  iframe { 
    width: 95%%; 
    height: 700px; 
  } 
</style> 
</head> 
<body> 

<img border="0" src="images/searchall.jpg" alt="Search all the Things" text="Search all the Things! width="50" height="100">

<form action="">
  People: <input type="text" name="people" />
  Company: <input type="text" name="company" />
  Nonprofit: <input type="text" name="nonprofit" />
  <input type="submit" value="Submit" />
</form>

<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="http://google.com/search?q=%(term)s" target="_blank">Open Google</a> </li>
<li><a href="http://www.linkedin.com/search/fpsearch?&type=people&keywords=%(term)s" 
target="_blank">Open LinkedIn</a></li>
<li><a href="http://scholar.google.com/scholar?hl=en&q=%(term)s" target="_blank">Open Google Scholar</a></li>
<li><a href="http://twitter.com/search?q=%(term)s" target="_blank">Open Twitter</a></li>
<li><a href="http://crunchbase.com/search?query=%(term)s" target="_blank">Open Crunchbase</a></li>
</ul>
</div>

%(frames)s 
 
<script>
  scroll(0,0);
</script>
</body> 
</html> 
"""

people_frames = """
<iframe src="http://www.wikipedia.org/wiki/Special:Search?search=%(term)s"></iframe> 
<iframe src="http://www.bing.com/search?q=%(term)s"></iframe> 
<iframe src="http://techcrunch.com/?s=%(term)s"></iframe> 
<iframe src="http://www.bgov.com/global_search/search?q=%(term)s"></iframe> 
<iframe src="http://www.spokeo.com/search?q=%(term)s"></iframe> 
"""

company_frames = """
<iframe src="http://www.wikipedia.org/wiki/Special:Search?search=%(term)s"></iframe> 
<iframe src="http://www.bing.com/search?q=%(term)s"></iframe> 
<iframe src="http://techcrunch.com/?s=%(term)s"></iframe> 
<iframe src="http://www.bgov.com/global_search/search?q=%(term)s"></iframe> 
<iframe src="http://ycharts.com/search?q=%(term)s"></iframe> 
<iframe src="http://www.amazon.com/s/ref=nb_sb_ss_i_0_8?url=search-alias%%3Daps&field-keywords=%(term)s"></iframe> 
<iframe src="http://www.govtrack.us/search?q=%(term)s"></iframe> 
<iframe src="http://sec.gov/cgi-bin/browse-edgar?match=&CIK=&filenum=&State=&Country=&SIC=&owner=exclude&Find=Find+Companies&action=getcompany&company=%(term)s"></iframe> 
"""

nonprofit_frames = """
<iframe src="http://www.wikipedia.org/wiki/Special:Search?search=%(term)s"></iframe> 
<iframe src="http://www.bing.com/search?q=%(term)s"></iframe> 
<iframe src="http://techcrunch.com/?s=%(term)s"></iframe>  
<iframe src="http://sec.gov/cgi-bin/browse-edgar?match=&CIK=&filenum=&State=&Country=&SIC=&owner=exclude&Find=Find+Companies&action=getcompany&company=%(term)s"></iframe> 
<iframe src="http://www.bgov.com/global_search/search?q=%(term)s"></iframe> 
<iframe src="http://990finder.foundationcenter.org/990results.aspx?990_type=&fn=%(term)s"></iframe> 
<iframe src="http://www.amazon.com/s/ref=nb_sb_ss_i_0_8?url=search-alias%%3Daps&field-keywords=%(term)s"></iframe> 
"""

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        people = self.request.get('people')
        company = self.request.get('company')
        nonprofit = self.request.get('nonprofit')
        if people:
            frames = people_frames % {'term': people}
	    term = people 
        elif company:
            frames = company_frames % {'term': company}
	    term = company
        else:
            frames = nonprofit_frames % {'term': nonprofit}
	    term = nonprofit
        self.response.out.write(doc % {'term': term, 'frames': frames})

application = webapp2.WSGIApplication([('/', MainPage)],
                              debug=True)
